<?php

/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, IsunCms.Com.
 * @license			http://www.isuncms.com/license.htm
 * @link				http://www.isuncms.com/
 * @since				Version 1.0 Beta
 * 
 */

require_once( dirname( strtr(__FILE__, '\\', '/') ).'/include/common.inc.php' );

ob_clean();

header( "Content-type: image/jpeg" ); 

$imageX = 65;
$imageY = 20;	

$im = function_exists( 'imagecreatetruecolor' )?@imagecreatetruecolor( $imageX, $imageY ):@imagecreate( $imageX, $imageY );

$key = rand(0,7); 	
$backColor = ImageColorAllocate( $im,250, 253, 254 );	//分配背景色（随机） 
$borderColor = ImageColorAllocate( $im, 133, 153, 193 );	//分配边框色 
$pointColor = ImageColorAllocate( $im, 180, 180, 180 );	//分配点颜色 
$fontColor = ImageColorAllocate( $im, 70, 70, 70 );//分配文字颜色
$lineColor = ImageColorAllocate( $im, 130, 130, 130 );//分配文字颜色
$foregroundArr = array
(
		imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
		imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
		imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
		imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255))
);

@imagefilledrectangle( $im, 0, 0, $imageX - 1, $imageY - 1, $backColor );//画一矩形并填充背景色
@imagerectangle( $im, 0, 0, $imageX-1, $imageY-1, $borderColor ); 	// 画一矩形并填充边框色

for( $i=0; $i<=50; $i++ )
{
	$pointX = rand( 2, $imageX-2 ); //点的X坐标
	$pointY = rand( 2, $imageY-2 ); //点的Y坐标
	@imagesetpixel( $im, $pointX, $pointY, $pointColor ); //画一个单一像素, 点。
}

$fontFamily = SUN_FONT."arialni.ttf";

$str_1 = random( 1 ); $str_2 = random( 1 ); $str_3 = random( 1 ); $str_4 = random( 1 );

imagettftext( $im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], $fontFamily, $str_1 );
imagettftext( $im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], $fontFamily, $str_2 );
imagettftext( $im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], $fontFamily, $str_3 );
imagettftext( $im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], $fontFamily, $str_4 );

Imagejpeg( $im );

set_cookie( 'authcode', array( 'authcode' => $str_1.$str_2.$str_3.$str_4, 'time' => 24*60*60 ) );

@ImageDestroy( $im ); 

